const express = require("express")
const { findBanner, updateBanner } = require("../service/bannerService")
const { formatResponse } = require("../utils/tool")
const { UnknownError } = require("../utils/error")

// 首页区域
const router = express.Router()

router.get("/", async function(req, res, next) {

    const result = await findBanner()
    if (result) {
        res.send(formatResponse(0, "", result))
    } else {

        res.send(new NotFoundError().toResponseJSONError())
    }
})

router.post("/", async function(req, res, next) {
    const result = await updateBanner(req.body)
    if (result) {
        res.send(formatResponse(0, "", result))
    } else {
        res.send(new UnknownError().toResponseJSONError())
    }
})

module.exports = router